package org.come.Jpanel;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.LingHelpBtn;
import com.tool.btn.SupportBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.come.Frame.ZhuFrame;
import org.come.entity.RoleSummoning;
import org.come.model.Lingbao;
import org.come.mouslisten.SystemMouslisten;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.SrcollPanelUI;
import org.come.until.UserMessUntil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;
import java.util.List;

public class LingHelpListJpanel extends JPanel {

	private JScrollPane jScrollPane; // 召唤兽列表滚动条
	private JList<Lingbao> listpet;// 召唤兽列表
	private DefaultListModel<Lingbao> listModel;// 放置召唤兽的对象
	private LingHelpBtn btntop,// 向上图标
			btnbottom,// 向下图标
			btntopset,// 置顶图标
			btnbottomset;// 置底图标
	private JLabel labOpen;
	private JLabel labLocking;
	public JLabel labgundong;
	public JLabel zhiyuan,shoufa;
	public LingHelpListJpanel() {


		BigDecimal zy = RoleData.getRoleData().getLoginResult().getScoretype("支援");
		BigDecimal sf = RoleData.getRoleData().getLoginResult().getScoretype("首发");
		zhiyuan = new JLabel();
		zhiyuan.setBounds(31,260,16,16);
		if(zy.intValue() == 1){
			zhiyuan.setIcon(SystemMouslisten.icon);
		}
		zhiyuan.addMouseListener(new MouseListener() {
			@Override
			public void mouseClicked(MouseEvent e) {

			}

			@Override
			public void mousePressed(MouseEvent e) {
				if(zhiyuan.getIcon() == null){
					zhiyuan.setIcon(SystemMouslisten.icon);
					String mes = Agreement.getAgreement().rolechangeAgreement("zy=1");
					SendMessageUntil.toServer(mes);
				}else{
					zhiyuan.setIcon(null);
					String mes = Agreement.getAgreement().rolechangeAgreement("zy=2");
					SendMessageUntil.toServer(mes);
				}
			}

			@Override
			public void mouseReleased(MouseEvent e) {

			}

			@Override
			public void mouseEntered(MouseEvent e) {

			}

			@Override
			public void mouseExited(MouseEvent e) {

			}
		});
		this.add(zhiyuan);

		shoufa = new JLabel();
		shoufa.setBounds(31,280,16,16);
		if(sf.longValue() != 0){
			zhiyuan.setIcon(SystemMouslisten.icon);
		}
		shoufa.addMouseListener(new MouseListener() {
			@Override
			public void mouseClicked(MouseEvent e) {

			}

			@Override
			public void mousePressed(MouseEvent e) {
				if(shoufa.getIcon() == null){
					shoufa.setIcon(SystemMouslisten.icon);
					RoleSummoning chosePetMes = UserMessUntil.getChosePetMes();
					BigDecimal summoningId = RoleData.getRoleData().getLoginResult().getSummoning_id();
					if(summoningId == null){
						ZhuFrame.getZhuJpanel().addPrompt2("请先设置参战召唤兽#46");
						return;
					}else {
						String mes = Agreement.getAgreement().rolechangeAgreement("sf=1");
						SendMessageUntil.toServer(mes);
					}
				}else{
					shoufa.setIcon(null);
					String mes = Agreement.getAgreement().rolechangeAgreement("sf=0");
					SendMessageUntil.toServer(mes);
				}
			}

			@Override
			public void mouseReleased(MouseEvent e) {

			}

			@Override
			public void mouseEntered(MouseEvent e) {

			}

			@Override
			public void mouseExited(MouseEvent e) {

			}
		});
		this.add(shoufa);

		if(MyIsif.getStyle().equals("水墨UI")) {
			this.setPreferredSize(new Dimension(293, 409));
			this.setLayout(null);
			this.setBackground(UIUtils.Color_BACK);
			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 622);
			offBtn.setBounds(293 - 37, 10, 25, 25);
			this.add(offBtn);

			zhiyuan.setBounds(50,370,16,16);
			shoufa.setBounds(150,370,16,16);


		}else {
			labgundong = new JLabel(new ImageIcon("img/xy2uiimg/gundongtiao_副本.png"));
			this.labgundong.setBounds(162, 64, 17, 169);
			this.add(this.labgundong);
			this.setPreferredSize(new Dimension(230, 320));
			this.setLayout(null);
			this.setBackground(UIUtils.Color_BACK);
			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/hongmu/s74.png", 1, 622);
			offBtn.setBounds(200, 5, 25, 25);
			this.add(offBtn);

		}




		listModel = new DefaultListModel<Lingbao>();

		// 召唤兽列表
		listpet = new JList<Lingbao>() {
			{
				setOpaque(false);
			} // instance initializer
		};
		DefaultListCellRenderer cellRenderer = new DefaultListCellRenderer() {
			@Override
			public Component getListCellRendererComponent(javax.swing.JList<?> list, Object value, int index,
														  boolean isSelected, boolean cellHasFocus) {
				super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
				Lingbao lb = (Lingbao)value;
				this.setText(lb.getBaoname()+"(" +lb.getBaoid()+")");
				return this;
			}
		};
		listpet.setSelectionBackground(new Color(33, 42, 52));
		listpet.setCellRenderer(cellRenderer);
		listpet.setFont(new Font("微软雅黑", 1, 14));
		listpet.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
		listpet.setForeground(Color.green);
		listpet.setSelectionForeground(Color.green);
		listpet.setModel(listModel);


		// 召唤兽列表滚动条
		jScrollPane = new JScrollPane(listpet);
		jScrollPane.setVerticalScrollBarPolicy(22);
		jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
		jScrollPane.getViewport().setOpaque(false);
		jScrollPane.setOpaque(false);
		if(MyIsif.getStyle().equals("水墨UI")) {
			jScrollPane.setBounds(55, 46, 194, 278);
		}else {
			jScrollPane.setBounds(30, 46, 149, 204);
			jScrollPane.setBorder(BorderFactory.createLineBorder(new Color(31, 7, 8)));
		}
		jScrollPane.setBorder(BorderFactory.createEmptyBorder());
		jScrollPane.setHorizontalScrollBarPolicy(31);
		this.add(jScrollPane);
		
		if(MyIsif.getStyle().equals("水墨UI")) {
			// 向上图标
			btntop = new LingHelpBtn("inkImg/button/B42.png", 1, 0, this);
			btntop.setBounds(258, 118, 17, 17);
			this.add(btntop);
			// 向下图标
			btnbottom = new LingHelpBtn("inkImg/button/B43.png", 1, 1, this);
			btnbottom.setBounds(258, 147, 17, 17);
			this.add(btnbottom);
			// 置顶图标
			btntopset = new LingHelpBtn("inkImg/button/19.png", 1, 2,"顶", this);
			btntopset.setBounds(258, 201, 18, 18);
			this.add(btntopset);
			// 置底图标
			btnbottomset = new LingHelpBtn("inkImg/button/19.png", 1, 3,"底", this);
			btnbottomset.setBounds(258, 230, 18, 18);
			this.add(btnbottomset);
		} else {
			this.labOpen = new JLabel();
			this.labOpen.setBounds(31, 261, 15, 15);
			this.add(this.labOpen);
			this.labLocking = new JLabel();
			this.labLocking.setBounds(31, 282, 15, 15);
			this.add(this.labLocking);
			// 向上图标
			this.btntop = new LingHelpBtn("img/xy2uiimg/42_png.button.btn_1.png", 1, 0, this);
			this.btntop.setBounds(188, 84, 20, 20);
			this.add(this.btntop);
			this.btnbottom = new LingHelpBtn("img/xy2uiimg/34_png.button.xy_vscroll$down.png", 1, 1, this);
			this.btnbottom.setBounds(188, 113, 20, 20);
			this.add(this.btnbottom);
			this.btntopset = new LingHelpBtn("img/xy2uiimg/topset.png", 1, 2, this);
			this.btntopset.setBounds(188, 167, 17, 17);
			this.add(this.btntopset);
			this.btnbottomset = new LingHelpBtn("img/xy2uiimg/bottomset.png", 1, 3, this);
			this.btnbottomset.setBounds(188, 196, 17, 17);
			this.add(this.btnbottomset);
		}

		zhiyuan.setVisible(false);
		shoufa.setVisible(false);


	}

	private ImageIcon icon;

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
//		if (icon == null)
			if(MyIsif.getStyle().equals("水墨UI")) {
				icon = new ImageIcon("inkImg/background/B254-1.png");
				// 背景
				g.drawImage(icon.getImage(), 0, 0, 293, 409, this);
			}else {
				icon = new ImageIcon("inkImg/hongmu/lbzy.png");
				// 背景
				g.drawImage(icon.getImage(), 0, 0, 230, 320, this);
			}



	}

	// 初始列表
	public void init(List<Lingbao> list) {
		listModel.clear();
		for (int i = 0; i < list.size(); i++) {
			listModel.addElement(list.get(i));
		}
	}

	public DefaultListModel<Lingbao> getListModel() {
		return listModel;
	}

	public void setListModel(DefaultListModel<Lingbao> listModel) {
		this.listModel = listModel;
	}

	public JList<Lingbao> getListpet() {
		return listpet;
	}

	public void setListpet(JList<Lingbao> listpet) {
		this.listpet = listpet;
	}

}
